package com.ly.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@FunctionalInterface
interface Foo{
    public int f1(int x,int y);


    public static int f3(int x,int y) {
        return x+y;
    }

    default int f4(int x,int y) {
        return x-y;
    }
}


class Ticket {
    private static int number = 30;

    private Lock lock = new ReentrantLock();
    public void sale() {
        lock.lock();
        try {
            if(number>0)
                System.out.println(Thread.currentThread().getName()+":"+number--);
        }catch (Exception e){

        }finally {
            lock.unlock();
        }

    }
}

public class SaleTicket {
    public static void main(String[] args) {
        Ticket t  = new Ticket();
        Foo f = (x,y) -> {return x/y;};

        for(int i=0;i<40;i++) {
           new Thread(() -> {t.sale();},"a").start();
           new Thread(() -> {t.sale();},"b").start();
           new Thread(() -> {t.sale();},"c").start();
        }

    }
}
